﻿@model  WaiGaoQiaoWeb.Models.OutStockVM
@{
    ViewBag.Title = "OutAddStorage";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("form", "validationEngine", "dp")
    @Html.Js("form", "validate", "unobtrusive", "inlinevalidation", "datepicker")
  
    <script type="text/javascript">
        $(document).ready(function () {
            $("form").makeValidationInline();
            $("#Article_NO").attr("readOnly", "true");
            $("#Article_Unit").attr("readOnly", "true");

            $("#OutDt1").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });

            //用户输入物品名称 带出这个物品的别的信息
            $("#Article_ID").bind("change", function () {
                $.post('@Url.Action("RtnStorageInfoForUnit", "Storage")', { "Id": $("#Article_ID").val() }, function (data) {
                    $("#Article_NO").val(data.ArticleNO);
                    TtnUnitList(data.ArticleUnit, data.ArticleUnitId);

                });
            });
            function TtnUnitList(ArticleUnit, ArticleUnitId) {
                $("#Article_Unit").children("option").remove();
                $("<option value='0' selected=selected>请选择... </option>").appendTo($("#Article_Unit"));
                if (ArticleUnit != null && ArticleUnit != "") {
                    var charUnit = ArticleUnit.split(',');
                    var charUnitId = ArticleUnitId.split(',');
                    if (charUnit.length > 0) {
                        for (var i = 0; i < charUnitId.length; i++) {
                            $("<option value=" + charUnitId[i] + ">" + charUnit[i] + " </option>").appendTo($("#Article_Unit"));
                        }
                    } //if
                } //if
            } //end
            var option = {
                height: 258,
                width: 790,
                url: '@Url.Action("GetDetailListByOrderNo")',
                dataType: 'json',
                colModel: [
                  { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                    { display: '调出日期', name: 'OutDt', width: 120, sortable: false, hide: false, align: 'left' },
			        { display: '劳保物品名称', name: 'Article_Name', width: 160, sortable: false, hide: false, align: 'left' },
                    { display: '物品编号', name: 'Article_NO', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '物品规格', name: 'Article_Unit', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '调出数量', name: 'Count', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '操作人', name: 'Operate', width: 120, sortable: false, hide: false, align: 'left' },
                     { display: '备注', name: 'Remark', width: 120, sortable: false, hide: false, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 120, sortable: false, hide: true, align: 'left' }
             	],
                title: false,
                singleselected: true,
                usepager: true,
                page: 1, //默认当前页  
                total: 1, //总页面数  
                useRp: true, //是否可以动态设置每页显示的结果数  
                rp: 15, // 每页默认的结果数  
                rpOptions: [10, 15, 20], //可选择设定的每页结果数
                showcheckbox: true,
                selectedonclick: true,
                //rowhandler: singleclick, //是否启用行的扩展事情功能,在生成行时绑定事件，如双击，右键等
                //onToggleCol: dblClick, //当在行之间转换时
                rowbinddata: true,
                query: $("#OrderNo").val()
            };
            var grid = $("#Outstock_T").flexigrid(option);

            //保存
            $("#btnSave").click(function (event) {
               if (!$("#frmGroupDetail").valid()) {
                   return false;
                }
                $('#frmGroupDetail').ajaxSubmit(function (callback) {
                    if (callback) {
                        $(":input").each(function () {
                            if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
                                $(this).val("");
                            }
                        });
                        $("#Article_NO").focus();
                        refresh();
                    }
                });
            }); //end save

            //关闭
            $("#btnCancel").click(function (e) {
                $(":input").each(function () {
                    if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
                        $(this).val("");
                    }
                });
                $("#Article_NO").focus();
                if ($("#ID").val() != "0") {
                    CloseModelWindow(null, true);
                    return false;
                }
                if (parent) {
                    for (var i = 0; i < parent.document.frames.length; i++) {
                        if (parent.document.frames[i].document.getElementById("orderno")) {
                            parent.document.frames[i].document.getElementById("orderno").value = $("#OrderNo").val();
                        }
                    }
                    CloseModelWindow(null, true);
                }
            });
            $("#btnDel").click(function () {
                if ($('.trSelected', grid).length == 0) {
                    showLoadingMsg("请选择要删除的行", { left: 300, top: 2 }, true, 3000);
                    return false;
                } else {
                    if (confirm("确定要删除吗?")) {
                        var rowcount = 0;
                        var items = $('.trSelected', grid);
                        for (var i = 0; i < items.length; i++) {
                            var id = items[i].id.substr(3);
                            $.ajax({
                                url: '@Url.Action("Delete")',
                                type: "POST",
                                data: { id: id },
                                async: false,
                                success: function (data) {
                                    if (data) {
                                        $("#Outstock_T").flexOptions(option).flexReload();
                                    }
                                },
                                error: function () {
                                }
                            });
                        } //for
                    }
                }
            });
            function refresh() {
                showLoadingMsg("操作成功", { left: 300, top: 2 }, true, 3000);
                $("#Outstock_T").flexOptions(option).flexReload();

            }
        })
    
    </script>
}
<div style="padding: 5px;">
    @using (Html.BeginForm("SaveOutDetail", "OutStock", FormMethod.Post, new { id = "frmGroupDetail" }))
    {
        @Html.ValidationSummary(true)
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.OrderNo)
        @Html.HiddenFor(model => model.RecordDateTime)
        <table style="width: 100%;">
            <tr>
                <td colspan="4">
                    <br />
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.OutDt1)
                </td>
                <td>@Html.TextBoxFor(model => model.OutDt1, new { @style = "width:145px;", @ReadOnly = true })
                    @Html.ValidationMessageFor(model => model.OutDt1)
                    <span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.Article_ID)
                </td>
                <td>
                    @Html.DropDownListFor(model => model.Article_ID, ViewBag.ArticleList as IEnumerable<SelectListItem>, new { @style = "width:145px;" })
                    @Html.ValidationMessageFor(model => model.Article_ID)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.Article_Unit)
                </td>
                <td>
                    @Html.DropDownListFor(model => model.Article_Unit, ViewBag.UnitList as IEnumerable<SelectListItem>, new { @style = "width:155px;height:20px;" })
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.Count)
                </td>
                <td>@Html.TextBoxFor(model => model.Count)
                    @Html.ValidationMessageFor(model => model.Count)
                    <span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.Article_NO)
                </td>
                <td>@Html.TextBoxFor(model => model.Article_NO)
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.Operate)
                </td>
                <td>@Html.TextBoxFor(model => model.Operate)
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.Remark)
                </td>
                <td colspan="3">
                    @Html.TextAreaFor(model => model.Remark, new { @style = "width:150px" })
                </td>
            </tr>
            <tr style="text-align: center;">
                <td>
                </td>
                <td>
                </td>
                <td colspan="2" align="right">
                    <a id="btnSave" class="button" href="javascript:void(0);"><span>保 存</span></a> <a
                        id="btnDel" class="button" href="javascript:void(0);"><span>删 除</span></a> <a id="btnCancel"
                            class="button" href="javascript:void(0);"><span>关 闭</span></a>
                </td>
            </tr>
        </table>
        <div style="overflow: scroll;">
            <table id="Outstock_T" style="display: none;">
            </table>
        </div>
 
    }</div>
